<?php
namespace app\admin\controller\common;

use app\BaseController;
use think\facade\Db;
use think\facade\Log;
use think\App;
use think\facade\View;
use think\facade\Request;

class Common extends BaseController
{
    public function stationUploadMoreImg()
    {
        return $this->uploadsMoreImg('station');
    }

    /**
     * 多图上传
     * @param $fieldName
     * @return $this
     */
    function uploadsMoreImg($fieldName){
        $file = $this->request->file("file");
        $dirDay = date("Y")."/".date("m");
        $fieldName = \think\facade\Filesystem::disk('index')->putFile("/image/".$fieldName."/".$dirDay,$file);
        if($fieldName){
            return $this->success('上传成功',"/upload/".$fieldName);
        }else{
            return $this->fail('上传失败');
        }
    }

    function imagesUploadImg(){
        $fieldName = $getData = Request::get('imgType') ? Request::get('imgType') : 'img';
        $file = $this->request->file("file");
        $dirDay = date("Y")."/".date("m");
        $fieldName = \think\facade\Filesystem::disk('index')->putFile("/image/".$fieldName."/".$dirDay,$file);
        if($fieldName){
            return $this->success('上传成功',"/upload/".$fieldName);
        }else{
            return $this->fail('上传失败');
        }
    }

    //获取经纬度
    function getSeat(){
        $getData = Request::post();
        if(!$getData['address']) return $this->fail('请填写地址');
        $url = 'https://api.map.baidu.com/geocoding/v3/?address='.$getData['address'].'&output=json&ak=Gzj5TBSWBixj2RlZAU3iMZXLRu5tcoou';
        $getInfo = $this->curlInfo($url,'GET');
        if($getInfo['status'] == 0){
            return $this->success('获取成功',$getInfo['result']);
        }else{
            return $this->fail('获取不到对应地址信息');
        }

    }

    //请求内容
    function curlInfo($url,$method,$bodys=''){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        if ($bodys) {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
        }else{
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        }
        $res = curl_exec($curl);
        curl_close($curl);
        return json_decode($res, true);
    }
  

}


